from langgraph.prebuilt import create_react_agent
from langchain_mcp_adapters.client import MultiServerMCPClient

from src.module.TongyiModel import TongyiModel

class McpClient(TongyiModel):
    def __init__(self):
        super().__init__()
        self.client = MultiServerMCPClient()

    async def start(self):
        async with MultiServerMCPClient(
                {
                    "weather": {
                        # make sure you start your weather server on port 8000
                        "url": "http://localhost:8000/sse",
                        "transport": "sse",
                    }
                }
        ) as client:
            agent = create_react_agent(self.model, client.get_tools())
            response = await agent.ainvoke({"messages": '深圳的天气怎么样?'})
            print(response)